import java.util.Arrays;
import java.util.HashMap;

public class Solution {
    public String[] sortPeople(String[] names, int[] heights) {
        int len = names.length;

        HashMap<Integer, String> map = new HashMap<>();

        for (int i = 0; i < len; i++) {
            map.put(heights[i], names[i]);
        }

        //从小到大排序
        Arrays.sort(heights);

        //反转数组
        for (int i = 0; i < len / 2; i++) {
            int temp = heights[i];
            heights[i] = heights[len - i - 1];
            heights[len - 1 - i] = temp;
        }

        //从map中获取身高与姓名的对应关系
        for (int i = 0; i < len; i++) {
            names[i] = map.get(heights[i]);
        }

        return names;
    }

    public String[] sortPeople2(String[] names, int[] heights) {
        int len = names.length;

        //height的下标数组
        Integer[] index = new Integer[len];

        for (int i = 0; i < len; i++) {
            index[i] = i;
        }

        Arrays.sort(index, (a, b) -> {
            return heights[b] - heights[a];
        });

        String[] ret = new String[len];
        for (int i = 0; i < len; i++) {
            ret[i] = names[index[i]];
        }

        return ret;
    }
}
